package com.example.a2212a_club_componse.pages

import android.graphics.drawable.Drawable
import android.widget.ImageView
import androidx.compose.foundation.Image
import androidx.compose.foundation.layout.size
import androidx.compose.material3.NavigationBar
import androidx.compose.material3.NavigationBarItem
import androidx.compose.material3.Scaffold
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.unit.dp
import androidx.navigation.NavDestination.Companion.hierarchy
import androidx.navigation.compose.currentBackStackEntryAsState
import androidx.navigation.compose.rememberNavController
import com.example.a2212a_club_componse.NavHomeOne
import com.example.a2212a_club_componse.R

data class NavItem(val path:String,val img:Int,val title:String)
@Composable
fun MainPage() {
       val list= listOf<NavItem>(NavItem("club",R.drawable.main_club,"俱乐部"),
              NavItem("play",R.drawable.main_playcar,"玩车"),
              NavItem("look",R.drawable.main_lookcar,"看车"),
              NavItem("message",R.drawable.main_message,"消息"),
              NavItem("mine",R.drawable.main_mine,"我的"))

       val navHostController = rememberNavController()
       val sta by navHostController.currentBackStackEntryAsState()
       val direction=sta?.destination
       Scaffold(bottomBar = {
              if(direction?.hierarchy?.any {
                     list.map {
                            navItem -> navItem.path
                     }.contains(it.route)
                     }==true){
                     NavigationBar {
                            list.forEach {
                                   NavigationBarItem(selected = false, onClick = {
                                          navHostController.navigate(it.path)
                                   }, icon = { Image( painterResource(id = it.img) , contentDescription ="", modifier = Modifier.size(30.dp) ) }, label = { Text(it.title) })
                            }
                     }
              }
       }) {

              NavHomeOne(it = it, navHostController = navHostController)
       }

}